<%@ taglib prefix="w" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/website/common/base.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${webname }-会员中心</title>
<%@ include file="/website/common/common.jsp"%>
<link href="${webctx }/css/manage.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/plugins/plupload2/plupload.full.min.js"></script>
</head>
<style>
    .warp-body{
        margin-bottom: 25px;
    }
    /*.dy-active{*/
        /*position: absolute;*/
        /*top: -12px;*/
        /*left: 2px;*/
        /*width: 100%;*/
        /*height: 12px;*/
        /*background: url(../images/ico-sign-active.png) no-repeat center top;*/
    /*}*/
</style>
<body>
<%@ include file="/website/common/top.jsp"%>
<%@ include file="/website/common/head.jsp"%>
<%@ include file="/website/common/menu.jsp"%>

<div class="warp-body" style="background-color: #fff;">
    <input type="hidden" name="days" value="${days}">
    <div id="rulejifen">


    </div>
    <div style="width: 100%; height: 3px; background-color: #0daeff;"></div>
	<div class="inner clearfix">
    	<div class="left-main">
        	<div class="left-inner">
            	<%@ include file="/website/user/left.jsp"%>
            </div>
        </div>
    	<div class="right-main">

        	<div class="right-inner">
                <!-- 用户信息 -->
                <div class="user-info">
                    <div class="user-date fl clearfix">
                        <span class="head-pic" id="uheadimg"><c:if test="${not empty user.photo}"><img src="${fileserver }${user.photo}" /></c:if><c:if test="${empty user.photo}"><img src="${webctx }/images/uhead.jpg" /></c:if></span>
                        <div class="user-date-text">
                            <div class="text-name-phone">
                                <span>${user.nickname }</span>
                                <span class="ico-phone">${user.phone }</span>
                            </div>
                            <div class="sign-btn">
                                <c:choose>
                                    <c:when test="${issign}">
                                        <a class="sign-btn-a" href="javascript:;" onclick="void(0);">已签到</a><span></span>
                                    </c:when>
                                    <c:otherwise>
                                        <a class="sign-btn-a" href="javascript:;" onclick="Sign()">签到</a><span></span>
                                    </c:otherwise>
                                </c:choose>

                                <div class="text-msg">
                                    ${integral_rule}

                                    <%--每日签到可获得50积分，--%>
                                    <%--累计3日连续签到可额外获得100积分，--%>
                                    <%--累积7日连续签到可额外获得200积分；--%>
                                    <%--连续签到7日后重新计算累计天数--%>
                                </div>
                            </div>
                            <div class="sign-day-list">
                                <!--
                                    选中的（不是当天的）cur
                                    选中的（是当天的）day-cur
                                    有活动的（即有个小旗的）day-active <span class="dy-active"></span>
                                 -->
                                <%--<c:if test="${signcount>1?'cur':''}"/>--%>
                                <ul>
                                    <%--<li class="day-item" id="day1">--%>
                                        <%--<span class="it-cicle"></span>--%>
                                        <%--<span class="item-txt">day1</span>--%>
                                    <%--</li>--%>
                                    <%--<li class="day-item day-active" id="day2">--%>
                                        <%--<span class="dy-active"></span>--%>
                                        <%--<span class="it-cicle"></span>--%>
                                        <%--<span class="day-line"></span>--%>
                                        <%--<span class="item-txt">day2</span>--%>
                                    <%--</li>--%>
                                    <%--<li class="day-item day-active" id="day3">--%>
                                        <%--<span class="dy-active"></span>--%>
                                        <%--<span class="it-cicle"></span>--%>
                                        <%--<span class="day-line"></span>--%>
                                        <%--<span class="item-txt">day3</span>--%>
                                    <%--</li>--%>
                                    <%--<li class="day-item" id="day4">--%>
                                        <%--<span class="it-cicle"></span>--%>
                                        <%--<span class="day-line"></span>--%>
                                        <%--<span class="item-txt">day4</span>--%>
                                    <%--</li>--%>
                                    <%--<li class="day-item" id="day5">--%>
                                        <%--<span class="it-cicle"></span>--%>
                                        <%--<span class="day-line"></span>--%>
                                        <%--<span class="item-txt">day5</span>--%>
                                    <%--</li>--%>
                                    <%--<li class="day-item" id="day6">--%>
                                        <%--<span class="it-cicle"></span>--%>
                                        <%--<span class="day-line"></span>--%>
                                        <%--<span class="item-txt">day6</span>--%>
                                    <%--</li>--%>
                                    <%--<li class="day-item day-active" id="day7">--%>
                                        <%--<span class="dy-active"></span>--%>
                                        <%--<span class="it-cicle"></span>--%>
                                        <%--<span class="day-line"></span>--%>
                                        <%--<span class="item-txt">day7</span>--%>
                                    <%--</li>--%>
                                </ul>
                            </div>

                        </div>
                    </div>
                    <div class="info-con fr clearfix">
                        <ul>
                            <a href="${ctx }/coupon/show">
                                <li>
                                    <p class="msg-tit msg-coupon">优惠券</p>
                                    <p class="msg-con">${user.couponcount}张</p>
                                </li>
                            </a>
                            <a href="${ctx }/user/integral">
                                <li>
                                    <p class="msg-tit msg-int">积分</p>
                                    <p class="msg-con" id="my_integral"><fmt:formatNumber value="${user.integral + user.ly_integral}" type="number"></fmt:formatNumber></p>
                                </li>
                            </a>
                            <a href="${ctx}/user/stationnews">
                                <li>
                                    <p class="msg-tit msg-news">消息</p>
                                    <p class="msg-con">${user.newstotal}</p>
                                </li>
                            </a>
                        </ul>
                    </div>
                </div>

                <!-- 最近订单 -->
                <div class="order-lately">
                    <div class="order-lat-nav">
                        <span>最近订单</span>
                        <a href="${ctx}/order/orderlist?pno=1&queryList=&timetype=&status=1">待付款 <em>${order.status1}</em></a>
                        <a href="${ctx}/order/orderlist?pno=1&queryList=&timetype=&status=3">待发货 <em>${order.status3}</em></a>
                        <a href="${ctx}/order/orderlist?pno=1&queryList=&timetype=&status=7">待收货 <em>${order.status7}</em></a>
                        <a href="${ctx}/order/orderlist?pno=1&queryList=&timetype=&status=11">已完成 <em>${order.status11}</em></a>
                    </div>

                    <div class="order-lat-con clearfix">
                        <c:choose>
                            <c:when test="${not empty order}">
                                <div class="img-list fl">
                                    <ul class="fl">
                                        <c:forEach items="${order.productlist}" var="product" begin="0" end="4">
                                            <li> <a href="${ctx }/product/info?priceid=${product.id}"><img src="<%=getRandomFileserver()%>${product.photo}" onerror="this.src='/website/images/noimg.jpg'" title="${product.productname}　${product.B_guige}"></a></li>
                                        </c:forEach>
                                    </ul>
                                    <c:if test="${order.productlist.size() > 5}">
                                        <span class="dot fl">...</span>
                                    </c:if>
                                </div>
                                <div class="order-msg clearfix">
                                    <ul>
                                        <li class="line-1" >${order.receipt_user}</li>
                                        <li class="line-2">
                                            <p>￥ ${order.pay_money}</p>
                                            <p>
                                                <c:if test="${order.paytype == '2'}">
                                                    货到付款
                                                </c:if>
                                                <c:if test="${order.paytype == '1'}">
                                                    在线支付
                                                </c:if>
                                            </p>
                                        </li>
                                        <li class="line-2">
                                            <p>${order.order_time}</p>
                                        </li>
                                        <li class="line-1" >${order.statustxt}</li>
                                        <li class="line-1" ><a href="${ctx}/order/showorderinfo?ordercode=${order.code}">查看</a></li>
                                    </ul>
                                </div>
                            </c:when>
                            <c:otherwise>
                                您还没有购买记录，赶快去下单吧
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>

                <!-- 我的收藏 -->
                <div class="my-collect">
                    <div class="collect-tit">
                        <span class="fl">我的收藏</span>
                        <span class="fr"><a href="${ctx }/product/favorites">查看全部</a></span>
                    </div>
                    <div class="collect-list">
                        <a class="list-btn list-prev" href="javascript:;" onclick="loadcollect_prev()"></a>
                        <a class="list-btn list-next" href="javascript:;" onclick="loadcollect_next()"></a>
                        <ul id="collect">

                        </ul>
                    </div>
                </div>

                <!-- 推荐 -->
                <div class="goods-recommend">
                    <div class="recommend-tit">根据您的浏览记录，为您推荐</div>
                    <ul class="clearfix">
                                <c:forEach items="${maylike.likelist}" var="like">
                                    <li>
                                        <a href="${ctx }/product/info?priceid=${like.id}" target="_blank"><img src="<%=getRandomFileserver()%>${like.photo}" onerror="this.src='/website/images/noimg.jpg'" title="${like.productname}  ${like.b_guige}" ></a>
                                        <p>${like.productname}  ${like.b_guige}</p>
                                        <c:choose>
                                            <c:when test="${!isuserauth}">
                                                <p class="price">审核通过可见</p>
                                            </c:when>
                                            <c:otherwise>
                                                <p class="price">￥${like.price}</p>
                                            </c:otherwise>
                                        </c:choose>
                                    </li>
                                </c:forEach>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" name="integralCount" value="0">

<input type="hidden" name="signcount" value="0">

<%@ include file="/website/common/foot-site.jsp"%>
<link type="text/css" rel="stylesheet" href="${webctx }/css/webeasyui.css">
<script type="text/javascript" src="${ctx}/plugins/oss/upload.js"></script>
<script type="text/javascript" src="${ctx }/util/js/easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx }/util/js/easyui-1.3.3/locale/easyui-lang-zh_CN.js" charset="utf-8"></script>
<script type="text/javascript" src="${ctx }/util/js/webui.js"></script>

</body>
</html>
<script>
    /**
     * 点击签到按钮
     */
    function Sign() {
        $w.httpRequest({
            url:apiroot+"/user/home/sign",
            data:{},
            ok:function(ret){
                var myIntegral = ret.Data;
                $("#my_integral").text(myIntegral.integral + myIntegral.ly_integral);
                var count = parseInt($("[name='signcount']").val());
                count++;
                $(".sign-btn-a").html("已签到" + "+" + getIntegral(count));
                $("#day"+count).addClass("day-cur");
            }
        })
    }
    var days = "";
    function getIntegral(count) {
        debugger;
        days = JSON.parse($("[name = 'days']").val());
        var integral = ${integral_today};

        var days_integrals = ${days_integrals};

        days_integrals = eval(days_integrals);

        for(var i = 0, len = days.length ; i < len ; i++){
            if(count == days[i]){
                integral += days_integrals[days[i]];
            }
        }
        return integral;

    }
    function showSign() {
        $w.httpRequest({
            url:"/user/signStatus",
            ok:function (ret) {
               var data =  ret.Data;
               var count = data.signcount;
               $("[name='signcount']").val(count);
               var h = "";
               for(var i = 0;i<count;i++){
                   if(i==0){
                       h += "<li class='day-item cur' id='day"+(i+1)+"'>"
                           + "<span class='it-cicle'></span>"
                           + "<span class='item-txt'>day"+(i+1)+"</span>"
                           + "</li>";
                   }else {
                       h += "<li class='day-item cur' id='day" + (i+1) + "'>"
                           + "<span class='it-cicle'></span>"
                           + "<span class='day-line'></span>"
                           + "<span class='item-txt'>day" + (i+1) + "</span>"
                           + "</li>"
                   }
               }
               if(data.issign){
                   if(i==0){
                       h += "<li class='day-item day-cur' id='day" + (++count) + "'>"
                           + "<span class='it-cicle'></span>"
                           + "<span class='item-txt'>day" + (++i) + "</span>"
                           + "</li>";
                   }else {
                       h += "<li class='day-item day-cur' id='day" + (++count) + "'>"
                           + "<span class='it-cicle'></span>"
                           + "<span class='day-line'></span>"
                           + "<span class='item-txt'>day" + (++i) + "</span>"
                           + "</li>";
                   }
               }

               for(;i<=6;i++){
                   if(i==0){
                       h += "<li class='day-item' id='day"+(i+1)+"'>"
                           + "<span class='it-cicle'></span>"
                           + "<span class='item-txt'>day"+(i+1)+"</span>"
                           + "</li>";
                   }else {
                       h += "<li class='day-item' id='day" + (i+1) + "'>"
                           + "<span class='it-cicle'></span>"
                           + "<span class='day-line'></span>"
                           + "<span class='item-txt'>day" + (i+1) + "</span>"
                           + "</li>"
                   }
               }
               $(".sign-day-list > ul").html(h);
                var days = JSON.parse($("[name = 'days']").val());
                var flag = days;
                for(var i=0;i<=flag.length;i++){
                    $("#day"+flag[i]).addClass("day-active");
                    $("#day"+flag[i]).prepend("<span class='dy-active'></span>");
                }
            }
        })
    };

    $(".sign-btn > span").hover(function () {
        $(".text-msg").show();
    },function () {
        $(".text-msg").hide();
    })
var uploader;
$(function(){
    showSign();
	//setLeftCur("zhugl");

	var plparm={
		runtimes : 'html5,flash,silverlight,html4',
		browse_button :'upheadbtn',
		url : ctx+'/upload/UploadPage@uploadPhoto.page?dir=head&tosave=false',
		flash_swf_url : ctx+'/plugins/plupload2/Moxie2.swf',
		silverlight_xap_url : ctx+'/plugins/plupload2/Moxie.xap',
		multi_selection:false,
		filters: {
			max_file_size : '500kb',
			prevent_duplicates :false, //不允许选取重复文件
		  	mime_types : [{ title : "图片文件", extensions : "jpg,png" }] //只允许上传图片文件
		},
        init:{
			FilesAdded: function(up, files) {
				uploader.start();
				previewImageOne(files[0],function(imgsrc){
					$("#uheadimg img").attr("src",imgsrc);
				})
			},
            FileUploaded:function(up,file,responseObject){
				var re=jQuery.parseJSON(responseObject.response);
				$w.httpRequest({
					url:apiroot+"/user/editsave",
					data:{"photo":re.url.replace(re.basepath,"")},
					ok:function(ret){
					}
				})
			},
            Error:function(up, err){
				if(err.code!="-602"){
					if(err.code=="-600")
						alert("图片大小不能超过500kb");
					else
						alert(err.code+"-"+err.message);
				}
				return false;
			}
		}
	};
	$oss.setUpDir("userhead");
	uploader=$oss.initUpload(plparm);
})
function saveinfo(){
	if($("[name='nickname']").val()==""){
		alert("请输入您的昵称");
		return;
	}
	$w.httpRequest({
		url:apiroot+"/user/editsave",
		data:{"nickname":$("[name='nickname']").val(),"type":"nick"},
		ok:function(ret){
			$web.correctMsg("保存成功");
		}
	})
}
function previewImageOne(file,callback){
	if(!file || !/image\//.test(file.type)) return;
	if(file.type=='image/gif'){
		var fr2 = new mOxie.FileReader();
		fr2.onload = function(){
			callback(fr2.result);
			fr2.destroy();
			fr2 = null;
		}
		fr2.readAsDataURL(file.getSource());
	}else{
		var preloader = new mOxie.Image();
		preloader.onload = function() {
			//preloader.downsize( 300, 300 );
			var imgsrc = preloader.type=='image/jpeg' ? preloader.getAsDataURL('image/jpeg',80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
			callback && callback(imgsrc);
			preloader.destroy();
			preloader = null;
		};
		preloader.load( file.getSource() );
	}
}
var pno = 1;
var ptotal = 1;
$(function () {
    loadhomeCollect(pno);
});
function loadhomeCollect(pno){
    loadCollect(6,myCollect,pno);
}
function loadcollect_prev() {
    if(pno>1){
        pno--;loadhomeCollect(pno);
    }
}
function loadcollect_next() {
    if(pno<ptotal){
        pno++;loadhomeCollect(pno);
    }
}
function loadCollect(size,fun,pno){
    var priceid=${user.id};
    var url=apiroot+'/product/collect?priceid='+priceid;
    if(pno)url+="&pno="+pno;
    $w.httpRequest({
        url:url,
        data:{},
        ok:function(ret){
            console.log(ret);
            fun(ret.Data);
        }
    })
}
function myCollect(datas) {
    var ul = $("#collect");
    ul.html("");
    var collectdatas = datas.list;
    if(collectdatas.length == 0) {
        ul.append("您尚未收藏任何商品");
    }
    ptotal = datas.pageCount;
    for(var i=0;i<collectdatas.length;i++){
        var data=collectdatas[i];
        var cjia=(data.b_chanjia?data.b_chanjia:"");
        if(cjia.length>15)cjia=cjia.substr(0,15)+"...";
        var h='<li class="collect-list-item">'
            +'<a href="'+ctx+'/product/info?priceid='+data.id+'" target="_blank"><img src="'+getRandomFileserver()+data.photo+'" onerror="this.src=\''+ctx+'/website/images/noimg.jpg\'" title="'+ data.productname +　' ' + (data.B_pzwh?data.B_guige:"") +'"/></a></div>'
            +'	<p>'+ data.productname +' ' + (data.B_pzwh?data.B_guige:"") +'</p>'
            +'</li>';
        ul.append(h);
    }
}
</script>